/*
 * @Descripttion:
 * @Copyright: 武汉一一零七科技有限公司©版权所有
 * @Link: 1074699502@qq.com
 * @Contact: QQ:1074699502
 * @LastEditors: wzb
 * @LastEditTime: 2020-11-18 18:29:46
 */
export default {
	data() {
		return {
			baseUrl: uni.getStorageSync('baseUrl'),
			shareModel: false, //分享遮罩层开启关闭
			shareImg: '', //分享海报
			shareTit: '', //分享标题
			shareText: '', //分享简介
			shareLink: '' //分享链接
		}
	},
	methods: {
		// type  0:图文     1:纯文字   2:纯图片    3:音乐   4:视频   5:小程序
		// scene    WXSceneSession:分享到聊天界面      WXSenceTimeline:分享到朋友圈     WXSceneFavorite:分享到微信关注
		goShareApp(provider = 'weixin', scene = 'WXSceneSession', type) {
			// this.$loading('拉取微信中...')
			uni.showLoading({
				title: '拉取微信中...'
			});
			uni.share({
				provider: provider,
				scene: scene,
				type: type,
				imageUrl: this.shareImg,
				success: res => {
					this.$http.getIntegralByShare({
					}).then(res => {})
					uni.showToast({
						title:'分享成功'
					})
				},
				fail: err => {
					uni.showToast({
						title:err
					})
				},
				complete: data => {
					uni.hideLoading();
				}
			})
		},
		copyShareLink() {
			this.$http.getIntegralByShare({
			}).then(res => {})
			uni.setClipboardData({
				data: this.shareLink,
				success: () => {
					uni.showToast({
						title:'复制成功'
					})
				}
			})
		},

		//    分享链接
		shareWebLink(provider = 'weixin', scene = 'WXSceneSession', type = 0) {
			uni.share({
				provider: provider,
				scene: scene,
				type: type,
				href: this.shareLink,
				title: this.shareTit,
				summary: this.shareText,
				success: res => {
					this.$toast('分享成功')
				},
				fail: err => {
					this.$toast(err)
				}
			});
		},
		removeHTMLTag(str) {
			str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
			str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
			//str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
			str = str.replace(/ /ig, ''); //去掉
			return str;
		},
		//多图分享
		multipleImgShare(list, copyText) {

			this.$copy(this.removeHTMLTag(copyText));

			list.map((element, index) => {
				this.savaImgAlbum(element, index)
			});
			setTimeout(() => {
				// #ifdef APP-PLUS
				plus.runtime.openURL('weixin://WXSceneTimeline');
				// #endif
			}, 1500);

		},
		// 系统分享
		otherShare() {
			this.$http.getIntegralByShare({
			}).then(res => {})
			uni.shareWithSystem({
				summary: this.shareText,
				href: this.shareLink,
				imageUrl: this.shareImg,
				success() {
					// 分享完成，请注意此时不一定是成功分享
				},
				fail() {
					// 分享失败
				}
			})
		},

		savaImgAlbum() {
			this.$http.getIntegralByShare({
			}).then(res => {})
			uni.downloadFile({
			    url: this.shareImg,
			    success: (res) => {
			        if (res.statusCode === 200) {
			            this.shareImg = res.tempFilePath
						console.log(this.shareImg)
						console.log(res);
			        }
			    }
			});

			this.$loading('下载中...')
			uni.saveImageToPhotosAlbum({
				filePath: this.shareImg,
				success: () => {
					this.$toast('分享图片已成功保存到相册')
				},
				fail: (res) => {
					console.log(res)
					this.$toast(JSON.stringify(res))
				}
			});
			setTimeout(() => {
				this.$hideLoading()
			}, 1000)
			
			
			
		}
	}
}
